class Solution(object):
    def longestMountain(self, arr):
        """
        :type arr: List[int]
        :rtype: int
        """
        state = 0
        left = 0
        right = 1
        n = len(arr)
        max_len = 0
        while right < n:
            if state == 0:
                if arr[right] > arr[right - 1]:
                    right += 1
                    continue
                else:
                    if arr[right] < arr[right - 1]:
                        if right - left >= 2:
                            max_len = max(max_len, right - left + 1)
                            state = 1
                        else:
                            left = right
                    else:
                        left = right
            else:
                if arr[right] > arr[right - 1]:
                    left = right - 1
                    state = 0
                else:
                    if arr[right] == arr[right - 1]:
                        left = right
                        state = 0
                    else:
                        max_len = max(max_len, right - left + 1)
            right += 1
        return max_len


data = Solution()
arr = [2, 1, 4, 7, 3, 2, 5]
print(data.longestMountain(arr))
